Skip to content

[SPARK-34342][SQL] Format DateLiteral and TimestampLiteral toString#31455

Closed
wangyum wants to merge 3 commits intoapache:masterfrom
wangyum:SPARK-34342
Closed

[SPARK-34342][SQL] Format DateLiteral and TimestampLiteral toString#31455
wangyum wants to merge 3 commits intoapache:masterfrom
wangyum:SPARK-34342

Conversation

@wangyum
Copy link
Member

@wangyum wangyum commented Feb 3, 2021

What changes were proposed in this pull request?

This pr format DateLiteral and TimestampLiteral toString. For example:

SELECT * FROM date_dim WHERE d_date BETWEEN (cast('2000-03-11' AS DATE) - INTERVAL 30 days) AND (cast('2000-03-11' AS DATE) + INTERVAL 30 days)

Before this pr:

Condition : (((isnotnull(d_date#18) AND (d_date#18 >= 10997)) AND (d_date#18 <= 11057))

After this pr:

Condition : (((isnotnull(d_date#14) AND (d_date#14 >= 2000-02-10)) AND (d_date#14 <= 2000-04-10))

Why are the changes needed?

Make the plan more readable.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test.

@wangyum wangyum requested review from cloud-fan and maropu February 3, 2021 09:54
@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39415/

@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Test build #134828 has finished for PR 31455 at commit d06db32.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39415/

@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39423/

@github-actions github-actions bot added the SQL label Feb 3, 2021
@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39423/

override def foldable: Boolean = true
override def nullable: Boolean = value == null

private val timeZoneId = DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we use def? we don't need to serialize it.

@SparkQA
Copy link

SparkQA commented Feb 3, 2021

Test build #134836 has finished for PR 31455 at commit c53f509.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


private val timeZoneId = DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)

override def toString: String = value match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have universal conversion of any literal to string via applying of the Cast expression to this literal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand your question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean this should be

override def toString: String = Cast(this, StringType, timeZoneId).eval().toString

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the @MaxGekk idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change the current behaviour:

Literal.create(Array[Byte](65, 66, 67), BinaryType).toString // before: 0x414243, after: ABC
Literal.create(Map("a" -> 1)).toString // before: map(keys: [a], values: [1]), after: {a -> 1}

cc @dongjoon-hyun

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pinging me, @wangyum .

Literal.create(Array("1", "2", "3"), ArrayType(StringType)))
}

test("Date/Timestamp toString") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe JIRA prefix in the test title.

@SparkQA
Copy link

SparkQA commented Feb 4, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39463/

@SparkQA
Copy link

SparkQA commented Feb 4, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39463/

@SparkQA
Copy link

SparkQA commented Feb 4, 2021

Test build #134875 has finished for PR 31455 at commit b36b57a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member

maropu commented Feb 5, 2021

LGTM except for the @MaxGekk comment.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 for this PR AS-IS because this is scoped preciously for Date/Timestamp literal.
For @MaxGekk 's suggestion, let's proceed in a different PR.

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Feb 7, 2021

@MaxGekk . Could you file a new JIRA and make a PR for your suggestion?
We can check the behavior change of BINARY/MAP in that PR independently.

@wangyum wangyum deleted the SPARK-34342 branch February 7, 2021 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants